# -*- coding: utf-8 -*-
"""
@Time ： 2024/1/27 0011 15:06
@Auth ： zpt
@File ：build_overview_page.py
@IDE ：PyCharm
"""
import time
from Page.base_page import BasePage
from Page.login_page import LoginPage
from Lib.readelement import Element
from Lib.log import log

build = Element('build_overview')


class Build_Overview_Page(BasePage):

    def login(self, url=None, name=None, password=None):
        """
        用户登录
        """
        login = LoginPage(self.driver)
        login.login(url, name, password)

    def alert_message(self):
        """
        获取弹窗元素
        """
        self.mouse_move(build["assert"])
        alert = self.find_element(build["assert"])

        return alert.text

    def enter_build_view(self):
        """
        进入build页签
        """
        try:
            self.click(build['build_overview'])
            time.sleep(1)
        except Exception as e:
            log.info("error: found build overview btn timeout")
            log.info(e)

    def check_elements(self, eles_list):
        """
         页面信息查询
        """
        try:
            flag = True
            for ele in eles_list:
                log.info('check element ' + ele)
                flag = self.is_element_exist(build[ele])
                if not flag:
                    break
            return flag
        except Exception as e:
            log.error('check element ' + ele + ' failed' + 'flag:' + str(flag), e)

    def goto_build_history(self):
        """
        进入构建历史页签
        """
        try:
            self.click(build['build_history'])
        except Exception as e:
            log.info("error: found build history btn timeout")
            log.info(e)

    def click_build_id(self):
        """
        点击构建构建id
        """
        try:
            self.click(build['build_id_btn'])
        except Exception as e:
            log.info("error: found build id timeout")
            log.info(e)

    def select_spec_name(self, name):
        """
        输入查找的spec名称
        """
        try:
            self.send_keys(build['search_spec_name'], name)
        except Exception as e:
            log.info("error: found seach box timeout")
            log.info(e)

    def get_spec_page_text(self):
        """
        获取detail列表的分页模式
        """
        try:
            spec_page=self.get_element_text(build['spec_page'])
            return spec_page
        except Exception as e:
            log.info("error: found spec page timeout")
            log.info(e)

    def click_build_operation(self):
        """
        点击构建中任务的operation按钮

        """
        try:
            spec_page=self.get_element_text(build['spec_page'])
        except Exception as e:
            log.info("error: found build operation timeout")
            log.info(e)